import java.util.Arrays;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-05-13
 * Time: 10:52
 */
public class TestSort {
    public static void testMergeSort(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long start = System.currentTimeMillis();
        Sort.mergeSort(arr);
        long end = System.currentTimeMillis();
        System.out.println("mergeSort:" + (end - start));
    }
    public static void testQuickSort2(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long start = System.currentTimeMillis();
        Sort.quickSort2(arr);
        long end = System.currentTimeMillis();
        System.out.println("quickSort2:" + (end - start));
    }
    public static void testQuickSort(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long start = System.currentTimeMillis();
        Sort.quickSort(arr);
        long end = System.currentTimeMillis();
        System.out.println("quickSort:" + (end - start));
    }
    public static void testBubbleSortSort(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long start = System.currentTimeMillis();
        Sort.bubbleSort(arr);
        long end = System.currentTimeMillis();
        System.out.println("bubbleSort:" + (end - start));
    }
    public static void testHeapSortSort(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long start = System.currentTimeMillis();
        Sort.heapSort(arr);
        long end = System.currentTimeMillis();
        System.out.println("heapSort:" + (end - start));
    }
    public static void testSelect0Sort(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long start = System.currentTimeMillis();
        Sort.selectSort0(arr);
        long end = System.currentTimeMillis();
        System.out.println("selectSort0:" + (end - start));
    }
    public static void testSelectSort(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long start = System.currentTimeMillis();
        Sort.selectSort(arr);
        long end = System.currentTimeMillis();
        System.out.println("selectSort:" + (end - start));
    }
    public static void testShellSort(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long start = System.currentTimeMillis();
        Sort.shellSort(arr);
        long end = System.currentTimeMillis();
        System.out.println("shellSort:" + (end - start));
    }
    public static void testInsertSort(int[] arr) {
        arr = Arrays.copyOf(arr, arr.length);
        long start = System.currentTimeMillis();
        Sort.insertSort(arr);
        long end = System.currentTimeMillis();
        System.out.println("insertSort:" + (end - start));
    }
    public static void orderArray(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            arr[i] = i;
        }
    }
    public static void inorderArray(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            arr[i] = arr.length - i;
        }
    }
    public static void randomArray(int[] arr) {
        Random random = new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i] = random.nextInt(100_0000);
        }
    }
    public static void main(String[] args) {
        int[] arr = new int[1000000];
        orderArray(arr);
        System.out.println("正序：");
//        testInsertSort(arr);
        testShellSort(arr);
//        testSelectSort(arr);
//        testSelect0Sort(arr);
        testHeapSortSort(arr);
//        testBubbleSortSort(arr);
        testQuickSort(arr);
//        testQuickSort2(arr);
        testMergeSort(arr);

        System.out.println("逆序：");
        inorderArray(arr);
//        testInsertSort(arr);
        testShellSort(arr);
//        testSelectSort(arr);
//        testSelect0Sort(arr);
        testHeapSortSort(arr);
//        testBubbleSortSort(arr);
//        testQuickSort(arr);
        testQuickSort2(arr);
        testMergeSort(arr);

        System.out.println("乱序：");
        randomArray(arr);
//        testInsertSort(arr);
        testShellSort(arr);
//        testSelectSort(arr);
//        testSelect0Sort(arr);
        testHeapSortSort(arr);
//        testBubbleSortSort(arr);
        testQuickSort(arr);
//        testQuickSort2(arr);
        testMergeSort(arr);
        Arrays.sort(arr);
    }
}
